
<?php 
require_once  __DIR__ . '/includes/authenticate.php';

if(isset($_POST['playerID'])){

	include_once './db_bb_connect.php'; 
	$playerID = $_POST['playerID'];

	$sql = "SELECT firstname, lastname 
			FROM users
			WHERE user_key = '$playerID'";

	$result=$db->query($sql);
	$row=$result->fetch_assoc();
	$firstname = $row['firstname'];
	$lastname = $row['lastname'];

	?>

<div id="container-fluid">
	<div id="row">
		<div id="col-md-12">
			<div class="table-responsive">
				<h4>Personal Points of Attention History for <?= $firstname ?> <?= $lastname ?></h4>
			<table class="table table-hover table-striped">
			    <thead>
			      <th>Date</th>
			      <th>Category</th>
			      <th>Point</th>
			      <th class="hidden-print">Visibility</th>
			      <th class="hidden-print">Edit</th>
			    </thead>

			    	<?php



			    	$sql = "SELECT * 
			    	FROM attentionpointsplayers
			    	WHERE playerID = '$playerID'
			    	ORDER BY date DESC";

			    	$result=$db->query($sql);

			    	while ($row=$result->fetch_assoc()) {

			    		$category = $row['category'];
			    		$text = $row['text'];
			    		$visibility = $row['visibility'];
			    		$timestamp = $row['date'];
			    		$timestampconv = strtotime($timestamp);
						$date = date("d-m-y", $timestampconv);
			    		$ID = $row['ID'];

			    		echo "
			    		<tr>
			    		<td> $date </td>
			    		<td> $category </td>
			    		<td> $text </td>
			    		<td class=\"hidden-print\"> $visibility </td>
			    		<td class=\"hidden-print\"> 
			    		<form id=\"\" class=\"pull-left\"> 
						<input type='hidden' name='ID' value='$ID'/>
						<input type='image' class='editpointofattention'  src='./images/edit_button.png' width=20px height=20px/> 
						</form>
							
						<form id=\"\" class=\"pull-left\"> 
						<input type='hidden' name='ID' value='$ID'/>
						<input type='image' class='deletepointofattention' src='./images/delete_button.png' width=20px height=20px/>
						</form>
						</td>
			    		</tr>
			    		";

			    	}
			    	?>
			    <tbody>
			    </tbody>
			    </table>
			</div>
		</div>
	</div>
</div>

<?php } ?>

<script type="text/javascript">
	

$(".editpointofattention").on("click", function(e) {
		postData = $(this.form).serialize();
		$.ajax({
 			type: "POST",
  			url: "./playerpointsofattention_edit.php",
  			data: postData,
  			success: function(data) { 
 				$("#fullplayerprofile").html(data);				
  			},
  			error: function (xhr, status, error) {
  				alert(xhr.responseText);
  			}
  		}); 
		e.preventDefault();		
});

$(".deletepointofattention").on("click", function(e) {
		postData = $(this.form).serialize();
		$.ajax({
 			type: "POST",
  			url: "./includes/handlers/playerpointsofattention_delete_handler.php",
  			data: postData,
  			success: function(data) { 
 				$("#fullplayerprofile").html(data);				
  			},
  			error: function (xhr, status, error) {
  				alert(xhr.responseText);
  			}
  		}); 
		e.preventDefault();		
});


	
</script>